import request from '@/utils/request'
// 定义接口类型
interface ArticleParams {
    page?: number;
    pageSize?: number;
    tag_id?: number | string;  // 修改参数名为 tag_id
}
interface ArticlePayload {
    title: string;
    content: string;
    description: string;
    thumbnail_url: string;
    author_id: number;
    category_id: number;
    status: 'draft' | 'published' | 'archived';
    tags: number[];  // 标签ID数组
}
// 文章相关接口
export const articleApi = {
    // 获取文章列表
    getArticles(params: ArticleParams) {
        return request({
            url: '/api/articles',
            method: 'get',
            params
        })
    },

    // 获取文章详情
    getArticleById(id: number) {
        return request({
            url: `/api/articles/${id}`,
            method: 'get'
        })
    },

    // 创建文章
    createArticle(data: ArticlePayload) {
        return request({
            url: '/api/articles',
            method: 'post',
            data
        })
    },

    // 更新文章
    updateArticle(id: number, data: any) {
        return request({
            url: `/api/articles/${id}`,
            method: 'put',
            data
        })
    },
    // 增加浏览量
    addView(id: number) {
        return request({
            url: `/api/articles/${id}/view`,
            method: 'put'
        })
    },
    // 删除文章
    deleteArticle(id: number) {
        return request({
            url: `/api/articles/${id}`,
            method: 'delete'
        })
    }
}